package tool.zyk.invoke;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * author: zyk
 * datetime: 2024/2/3 23:29
 * describe:
 */
public abstract class AbstractReflectExecutor implements ReflectExecutor {
    @Override
    public Object doInvoke(Method method, Object[] args) throws InvocationTargetException, IllegalAccessException, InstantiationException {
        Class<?> declaringClass = method.getDeclaringClass();
        Object obj = getObj(declaringClass);
        return method.invoke(obj, args);
    }

    abstract protected <T> T getObj(Class<T> tClass) throws InstantiationException, IllegalAccessException;
}
